package com.focus.pay.wx.constant;


import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

/**
 * @author 赵参谋
 * @version $
 * =========================================================================
 * 变更履历：
 * -------------------------------------------------------------------------
 * 变更编号     变更时间    变更人   变更原因    变更内容
 * -------------------------------------------------------------------------
 * <p>
 * @description：微信支付常量
 * @date 2021/12/31 10:01
 **/
public class WxPayConstant {

    /**
     * 微信支付V2请求PATH
     */
    @Getter
    public enum WxPayPathV2 {
        QUERY_ORDER                 ("/pay/orderquery", "微信支付结果查询"),
        CANCEL_ORDER                ("/secapi/pay/reverse", "微信撤销订单"),
        REFUND_ORDER                ("/secapi/pay/refund", "微信申请退款"),
        REFUND_QUERY                ("/pay/refundquery", "微信退款查询"),
        TRADE_DOWNLOAD              ("/pay/downloadbill", "微信下载交易账单"),
        PAY_ORDER_UNIFIED           ("/pay/unifiedorder", "微信通用下单"),
        PAY_ORDER_BAR               ("/pay/micropay", "微信付款码支付"),
        ;

        private String path;
        private String desc;

        WxPayPathV2(String path, String desc) {
            this.path = path;
            this.desc = desc;
        }

        /**
         * 构建请求路径
         *
         * @return 请求路径
         */
        public static String buildRequestPath(WxPayPathV2 wxPayPathV2) {
            return WxPayDomain.API_DOMAIN_V1.getDomain().concat(wxPayPathV2.getPath());
        }
    }

    /**
     * 微信支付V3请求PATH
     */
    @Getter
    public enum WxPayPathV3 {
        PAY_ORDER_UNIFIED               ("/v3/pay/transactions/%s", "微信通用下单"),
        QUERY_ORDER_TRANSACTION         ("/v3/pay/transactions/id/%s?mchid=%s", "微信支付-订单号查询"),
        QUERY_ORDER_OUTTRADENO          ("/v3/pay/transactions/out-trade-no/%s?mchid=%s", "微信支付-商户单号查询"),
        CANCEL_ORDER                    ("/v3/pay/transactions/out-trade-no/%s/close", "微信关闭订单"),
        REFUND_ORDER                    ("/v3/refund/domestic/refunds", "微信申请退款"),
        REFUND_QUERY                    ("/v3/refund/domestic/refunds/%s", "微信退款查询"),
        TRADE_BILL                      ("/v3/bill/tradebill?bill_date=%s&bill_type=%s&tar_type=GZIP", "微信交易账单"),
        FUNDFLOW_BILL                   ("/v3/bill/fundflowbill?bill_date=%s&account_type=%s&tar_type=GZIP", "微信资金账单"),
        TRADE_DOWNLOAD                  ("%s", "账单下载"),
        Pay_COMBINE_ORDER_UNIFIED       ("/v3/combine-transactions/%s", "微信合单支付"),
        ;

        private String path;
        private String desc;

        WxPayPathV3(String path, String desc) {
            this.path = path;
            this.desc = desc;
        }

        /**
         * 获取请求路径
         *
         * @param wxPayPathV3 请求路径
         * @param params      请求参数
         * @return 请求路径
         */
        public static String buildRequestPath(WxPayPathV3 wxPayPathV3, String... params) {
            String requestPath = WxPayDomain.API_DOMAIN_V1.getDomain().concat(wxPayPathV3.getPath());
            if (ObjectUtil.isNotEmpty(params)) String.format(requestPath, params);
            return requestPath;
        }

        /**
         * 获取请求绝对URL,去除域名
         *
         * @param wxPayPathV3 请求路径
         * @param params      请求参数
         * @return 请求绝对UR
         */
        public static String buildRequestRoute(WxPayPathV3 wxPayPathV3, String... params) {
            String requestRoute = wxPayPathV3.getPath();
            if (ObjectUtil.isNotEmpty(params)) String.format(requestRoute, params);
            return requestRoute;
        }


    }

    /**
     * 微信域名
     */
    @Getter
    public enum WxPayDomain {
        API_DOMAIN_V1("https://api.mch.weixin.qq.com"),
        API_DOMAIN_V2("https://api2.mch.weixin.qq.com"),
        ;

        private String domain;

        WxPayDomain(String domain) {
            this.domain = domain;
        }
    }

    /**
     * 微信结果状态
     */
    @Getter
    public enum WxPayStatus {
        SUCCESS
    }

    /**
     * 微信加密方式
     */
    @Getter
    public enum WxPayEncryptionType {
        MD5, HMACSHA256, SHA256_RSA,
    }

}




